//
//  SleepRequest.m
//  SleepingElf
//
//  Created by karong on 2023/10/18.
//

#import "SleepRequest.h"
#import "SleepModel.h"

@implementation SleepRequest
+ (void)loadTipAndListenListWithSuccess:(AnyObjectBlock)success failed:(Failure)failed {
    NSString * url = API_SLEEP_LISTEN_LIST;
    NSDictionary * parameters = @{};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        SleepModel * sleepModel = [SleepModel mj_objectWithKeyValues:responseDict[@"data"]];
        success(sleepModel);
    } failure:failed];
}

+ (void)collectMusicWithMusic_id:(NSInteger)music_id success:(EmptyBlock)success failed:(Failure)failed {
    NSString * url = API_MUSIC_COLLECT;
    NSDictionary * parameters = @{@"music_id":@(music_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [SEToast simple:WSLocalized(@"已添加至【我的收藏】")];
        success();
    } failure:failed];
}

+ (void)deleteCollectMusicWithMusic_id:(NSInteger)music_id success:(EmptyBlock)success failed:(Failure)failed {
    NSString * url = API_MUSIC_COLLECT_DELETE;
    NSDictionary * parameters = @{@"music_id":@(music_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        success();
    } failure:failed];
}

+ (void)collectCustomMusicWithMusicArray:(NSArray *)musicArray title:(NSString *)title success:(EmptyBlock)success failed:(Failure)failed {
    NSString * url = API_CUSTOM_MUSIC_COLLECT;
    NSMutableArray * array = [NSMutableArray new];
    for (MusicModel * music in musicArray) {
        //[{"id":1,"volume":80},{"id":3,"volume":100},{"id":2,"volume":100}]
        NSDictionary * dic = @{@"id":@(music.id), @"volume":@([[PlayerManager shared]playerVolumeWithMusic:music] * 100)};
        [array addObject:dic];
    }
    NSDictionary * parameters = @{@"list":array.jsonStringEncoded,
                                  @"title":SEEmptyStr(title)
    };
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        [SEToast simple:WSLocalized(@"已添加至【我的收藏】")];
        success();
    } failure:failed];
}

+ (void)deleteCollectCustomMusicWithMusic_id:(NSInteger)music_id success:(EmptyBlock)success failed:(Failure)failed {
    NSString * url = API_CUSTOM_MUSIC_COLLECT_DELETE;
    NSDictionary * parameters = @{@"id":@(music_id)};
    [self postWithURLString:url parameters:parameters success:^(NSDictionary * _Nonnull responseDict) {
        success();
    } failure:failed];
}
@end
